package com.happymmall.service.impl;

import com.happymmall.dao.BaseDao;
import com.happymmall.dao.ShippingDao;
import com.happymmall.dao.UserDao;
import com.happymmall.dao.impl.ShippingDaoImpl;
import com.happymmall.dao.impl.UserDaoImpl;
import com.happymmall.entity.Shipping;

import java.sql.Connection;
import java.sql.SQLException;

public class ShippingServiceImpl implements com.happymmall.service.ShippingService {
    private ShippingDao shippingDao;

    //无参构造器，一创建UserService对象就可以，创建UserDao对象
    public ShippingServiceImpl() {

        shippingDao = (ShippingDao) new ShippingDaoImpl();
    }

    @Override
    public int addShipping(Shipping shipping) {
        Connection connection = null;
        int result = 0;
        try {
            // 加载驱动获取链接
            connection = BaseDao.getConnection();
            // 通过业务层调用对应的具体的数据库操作

            //执行插入
            result = shippingDao.addShipping(connection, shipping);

        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            BaseDao.closeResource(connection, null, null);
        }
        return result;


    }

    @Override
    public int deleteShipping(Integer shippingId) {
        return 0;
    }

    @Override
    public int updateShipping(Shipping shipping) {
        return 0;
    }

    @Override
    public Shipping selectShipping(Integer shippingId) {
        return null;
    }
}
